//
//  TJTableController.m
//  CrossBorderPayment
//
//  Created by hc-101 on 2020/6/9.
//  Copyright © 2020 xtjun. All rights reserved.
//

#import "TJTableController.h"
 
#import "UIScrollView+EmptyDataSet.h"

@interface TJTableController ()<DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>

@end

@implementation TJTableController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.emptyText = @"暂无数据".localizedString;
    self.emptyImageName = @"mXiaoxi";
    self.allowEmptyScroll = NO;
    if (self.hiddenNavigationBar == NO) {
        self.verticalOffset = -150;
    }
    
}

- (UITableView *)tableView {
    if (!_tableView) {
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:self.tableViewStyle];
        tableView.separatorColor = [UIColor tj_separatorColor];
        tableView.backgroundColor = [UIColor tj_backgroundColor];
        tableView.tableFooterView = [[UIView alloc] init];
        tableView.showsHorizontalScrollIndicator = NO;
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.emptyDataSetSource = self;
        tableView.emptyDataSetDelegate = self;
        if (@available(iOS 11.0, *)) {
            tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            tableView.estimatedSectionHeaderHeight = 0;
            tableView.estimatedSectionFooterHeight = 0;
            tableView.estimatedRowHeight = 0;
        }
        [self.view addSubview:tableView];
        _tableView = tableView;
    }
    return _tableView;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return nil;
}

- (nullable UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    return [UIImage imageNamed:self.emptyImageName];
}

- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView {
    return self.displayEmpty;
}

- (nullable UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView {
    return [UIColor clearColor];
}

- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
    return _verticalOffset;
}

- (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView {
    return 18;
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
    return _allowEmptyScroll;
}

- (nullable NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    
    NSString *text = self.emptyText;
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
    [attStr addAttribute:NSFontAttributeName
                   value:[UIFont systemFontOfSize:13]
                   range:NSMakeRange(0, text.length)];
    [attStr addAttribute:NSForegroundColorAttributeName
                   value:UIColor_Hex(0x999999)
                   range:NSMakeRange(0, text.length)];
    return attStr;
}


@end
